import java.util.*;

public class Test {
    public static int sum1 = 0;
    public static int sum2 = 0;
    public static void main(String[] args) throws InterruptedException {
        Random random = new Random();
        int[] array = new int[1000_0000];
        for(int i = 0; i < array.length; i++){
            array[i] = random.nextInt(101);
        }
        //线程1计算偶数和
        Thread t1 = new Thread(() -> {
            for(int i = 0; i < array.length; i++){
                if(array[i] % 2 == 0){
                    sum1 += array[i];
                }
            }
        });
        //线程二计算所有奇数和
        Thread t2 = new Thread(() -> {
            for(int i = 0; i < array.length; i++){
                if(array[i] % 2 != 0){
                    sum2 += array[i];
                }
            }
        });
        //记录时间
        long start = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long end = System.currentTimeMillis();
        int sum = sum1 + sum2;
        System.out.println("运行时间:" + (end - start) + "ms");
        System.out.println("sum = " + sum);

    }
}
